// pages/index/component/notice/notice.js
import {
  list,
  tag
} from '../../../../api/article';
const util = require('../../../../utils/util.js')
let app = getApp()
Component({
  lifetimes: {
    attached() {
      if(!util.isNull(this.data.info.linkId)){
        this.data.linkId = this.data.info.linkId
      }
      this.initQuestion()
    },
  },
  /**
   * 组件的属性列表
   */
  properties: {
    info: {
      type: Object,
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    notice: null,
    tagIds: '',
    linkId:null
  },

  /**
   * 组件的方法列表
   */
  methods: {
    initQuestion() {
      let params = {
        'mchId': app.globalData.mchId,
        'type': 0,
      }
      tag(params).then(res => {
        res.data.data.forEach(item => {
          if (item.name === '通知公告') {
            this.data.tagIds = item.id
            // 查找常见问题
            list({
              'mchId': app.globalData.mchId,
              'tagIds': this.data.tagIds,
              'sortField': "id",
              'sortType': 'desc'
            }).then(res => {
              if (res.data.data.length > 0) {
                this.data.notice = res.data.data[0]
              }
              this.setData({
                notice: this.data.notice
              })

            }).catch(err => {
              console.log(err)
            })
          }
        })
      }).catch(err => {
        console.log(err)
      })

    },
    detailClick() {
      // let id = data.currentTarget.dataset.id
      if (this.data.notice == null) {
        return;
      }
      let id = this.data.notice.id
      wx.navigateTo({
        url: `/pages/member/detail/detail?id=${id}`,
      })
    },
    toMore(){
      if(this.data.linkId == null){
        return;
      }else{
        let id = this.data.linkId
        wx.navigateTo({
          url: `/pages/index/wxPage/wxPage?id=${id}`
        })
      }
    },
  }
})
